//
//  RHDeviceTypeCircleView.m
//  RuiHeAppApp
//
//  Created by Yan Chen on 2023/8/10.
//

#import "RHDeviceTypeCircleView.h"
@interface RHDeviceTypeCircleView()

@end
@implementation RHDeviceTypeCircleView
- (instancetype)init
{
    if([super init]){
        self.backgroundColor = [UIColor whiteColor];
        self.color1 = [UIColor colorWithHexString:@"7766E5" alpha:0.4];
        
    }
    return self;
}
-(void)setPercent:(CGFloat)percent
{
    _percent = percent;
    [self setNeedsDisplay];
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    [self setNeedsDisplay];
}
- (void)drawRect:(CGRect)rect {
    CGPoint center = CGPointMake(self.width/2, self.height/2);
    CGFloat  bigLineWidth = 6;
    CGFloat  smallLineWidth = 4;;
    CGFloat  bigRadius = MIN(self.width, self.height)/2 - bigLineWidth/2;
    CGFloat  smallRadius = bigRadius;
    
    UIBezierPath *totalPath = [UIBezierPath bezierPathWithArcCenter:center radius:smallRadius startAngle:0 endAngle:M_PI*2 clockwise:YES];
    totalPath.lineWidth = smallLineWidth;
    [self.color1 setStroke];
    [totalPath stroke];
    
    if(self.percent == 0)return;
    
    CGFloat startAngle = self.randomAngle * M_PI/180;
    CGFloat endAngle = startAngle + self.percent*2*M_PI;
    UIBezierPath *currentPath = [UIBezierPath bezierPathWithArcCenter:center radius:bigRadius startAngle:startAngle endAngle:endAngle clockwise:YES];
    currentPath.lineCapStyle = kCGLineCapRound;
    currentPath.lineWidth = bigLineWidth;
    [self.color2 setStroke];
    [currentPath stroke];
    
    
}


@end
